coord_map
Projects a portion of the earth, which is approximately spherical, onto a flat 2D plane using any projection defined by the mapproj package and then convert them with ggplotly.
p <- if (require("maps")) { nz <- map_data("nz") # Prepare a map of NZ nzmap <- ggplot(nz, aes(x = long, y = lat, group = group)) + geom_polygon(fill = "white", colour = "black") # Plot it in cartesian coordinates nzmap }
plotly::ggplotly(p)
p <- if (require("maps")) { # With correct mercator projection nzmap + coord_map() }
plotly::ggplotly(p)
p <- if (require("maps")) { # With the aspect ratio approximation nzmap + coord_quickmap() }
plotly::ggplotly(p)
p <- if (require("maps")) { # Other projections nzmap + coord_map("azequalarea", orientation = c(-36.92, 174.6, 0)) }
plotly::ggplotly(p)
p <- if (require("maps")) { states <- map_data("state") usamap <- ggplot(states, aes(long, lat, group = group)) + geom_polygon(fill = "white", colour = "black") # Use cartesian coordinates usamap }
plotly::ggplotly(p)
p <- if (require("maps")) { # With mercator projection usamap + coord_map() }
plotly::ggplotly(p)
p <- if (require("maps")) { # See ?mapproject for coordinate systems and their parameters usamap + coord_map("gilbert") }
plotly::ggplotly(p)
p <- if (require("maps")) { # For most projections, you'll need to set the orientation yourself # as the automatic selection done by mapproject is not available to # ggplot usamap + coord_map("orthographic") }
plotly::ggplotly(p)
p <- if (require("maps")) { usamap + coord_map("conic", lat0 = 30) }
plotly::ggplotly(p)
p <- if (require("maps")) { usamap + coord_map("bonne", lat0 = 50) }
plotly::ggplotly(p)
if (FALSE) { if (require("maps")) { # World map, using geom_path instead of geom_polygon world <- map_data("world") worldmap <- ggplot(world, aes(x = long, y = lat, group = group)) + geom_path() + scale_y_continuous(breaks = (-2:2) * 30) + scale_x_continuous(breaks = (-4:4) * 45) # Orthographic projection with default orientation (looking down at North pole) worldmap + coord_map("ortho") } if (require("maps")) { # Looking up up at South Pole worldmap + coord_map("ortho", orientation = c(-90, 0, 0)) } if (require("maps")) { # Centered on New York (currently has issues with closing polygons) worldmap + coord_map("ortho", orientation = c(41, -74, 0)) } }
## Error in UseMethod("api_create"): no applicable method for 'api_create' applied to an object of class "shiny.tag"